const path = require('path')
const fs = require('fs')
const {AutoWebPlugin} = require('web-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')

const autoPlugin = new AutoWebPlugin(
//所有页面的入口目录
'./src/pages', {
  //所有页面采用的模版文件
  template: './src/template.html',
  commonsChunk: {
    name: 'common', // 必填属性,输出的文件名称
    minChunks: 4, // 来自 CommonsChunkPlugin 插件
  },
  entry: null
})

module.exports = {
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'js/[name].js'
  },
  entry: autoPlugin.entry(),
  module: {
    rules: [
      {
        test: /\.js$/,
        // cacheDirectory 缓存babel编译结果加快重新编译速度
        loader: 'babel-loader?cacheDirectory',
        // 只命中src目录里的js文件，加快webpack搜索速度
        include: path.resolve(__dirname, 'src')
      }, {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: 'css-loader'
        })
      }, {
        test: /\.(gif|png|jpe?g|eot|woff|ttf|svg|pdf)$/,
        loader: 'file-loader',
        options: {
          name: 'img/[name]_[hash].[ext]'
        }
      }, {
        test: /\.art$/,
        loader: "art-template-loader",
        options: {}
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('css/[name].css'),
    autoPlugin
  ]
}
